package com.crk.shixiguanli.controller;

import com.crk.shixiguanli.entity.College;
import com.crk.shixiguanli.service.CollegeService;
import com.crk.shixiguanli.util.LayUiTableJson;
import com.crk.shixiguanli.util.Page;
import com.crk.shixiguanli.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author
 * @description:
 * @date 2020/4/6
 */
@RestController
@RequestMapping("college")
public class CollegeController {
    @Autowired
    CollegeService collegeService;

    @RequestMapping("manage")
    public ModelAndView manage(){
        ModelAndView modelAndView = new ModelAndView("/workspace/college/collegeList.html");
        return modelAndView;
    }

    @GetMapping("detail")
    public ModelAndView detail(){
        ModelAndView modelAndView = new ModelAndView("/workspace/college/collegeAdd.html");
        return modelAndView;
    }

    @GetMapping("guide")
    public ModelAndView guide(){
        ModelAndView modelAndView = new ModelAndView("/workspace/college/guide.html");
        return modelAndView;
    }

    @GetMapping("guideDetail")
    public ModelAndView guideDetail(){
        ModelAndView modelAndView = new ModelAndView("/workspace/college/guideDetail.html");
        return modelAndView;
    }

    @RequestMapping("queryCollegePage")
    public LayUiTableJson queryCollegePage(@RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        ResponseResult ResponseResult = collegeService.queryCollegePage(pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)ResponseResult.getData());
        return layUiTableJson;
    }

    @RequestMapping("queryCollege")
    public ResponseResult queryCollege(){
        return collegeService.queryCollege();
    }

    @RequestMapping("getCollege")
    public ResponseResult getCollege(@RequestParam("id") Integer id){
        return collegeService.getCollege(id);
    }

    @RequestMapping("saveCollege")
    public ResponseResult saveCollege(College college){
        return collegeService.saveCollege(college);
    }

    @RequestMapping("deleteCollege")
    public ResponseResult deleteCollege(@RequestParam("id") Integer id){
        return collegeService.deleteCollege(id);
    }

    @RequestMapping("getCollegeByName")
    public ResponseResult getCollegeByName(@RequestParam("collegeName") String collegeName){
        return collegeService.getCollegeByName(collegeName);
    }
}
